using Brouteforce.NewManagers;
using Brouteforce.UserInterface.Abstracts;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Brouteforce.UserInterface.UIControls
{
    public delegate void OnClickHandler();

    public class Button : AbstractUIControl
    {
        public event OnClickHandler OnClick;
        private Texture2D _image;

        public Button(Texture2D image, string name, Rectangle surroundingRectangle)
            : base(name, surroundingRectangle)
        {
            _image = image;
        }

        public override void Update()
        {
            if (InputManager.Instance.MouseClicked.IsChangedSince(BFGame.LoopIndex) && InputManager.Instance.IsMouseClickedOn(CurrentUIcontrolRectangle)) {
                if (OnClick != null) OnClick();
            }
        }

        public override void Draw(GameTime gameTime)
        {
            BFGame.SpriteBatch.Draw(_image, new Rectangle(CurrentUIcontrolRectangle.X, CurrentUIcontrolRectangle.Y, RelativeUIcontrolRectangle.Width, RelativeUIcontrolRectangle.Height), Color.White);
        }
    }
}
